Public NotInheritable Class frmWavelengths
    Private m_objMyWavelengths As MyWavelengths
    Private m_WavelengthList As New List(Of Double)

    Public Sub New(ByVal wavelenghts As MyWavelengths)
        ' This call is required by the Windows Form Designer.
        Me.InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        m_objMyWavelengths = wavelenghts
        For intWavelength As Integer = 1 To m_objMyWavelengths.Count
            m_WavelengthList.Add(m_objMyWavelengths.Item(intWavelength))
        Next
        Me.FillList()
        Me.Translate()
    End Sub


    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim decValue As Decimal

        Try
            decValue = Decimal.Parse(Me.txtNewValue.Text, Globalization.NumberStyles.Any)
        Catch ex As Exception
            Me.txtNewValue.Text = Nothing
            Me.txtNewValue.Focus()
            Exit Sub
        End Try
        Try
            m_objMyWavelengths.Add(decValue)
        Catch ex As MyWavelengths.WavelengthException
            MessageBox.Show(ex.Message, My.Application.Info.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End Try
        Me.FillList()
    End Sub

    Private Sub btnDefault_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDefault.Click
        m_objMyWavelengths.SetDefaultValues()
        Me.FillList()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        m_objMyWavelengths.RemoveAt(Me.lvwWavelengths.SelectedIndices.Item(0) + 1)

        '0.9.4
        If m_objMyWavelengths.Count = 0 Then m_objMyWavelengths.SetDefaultValues()

        Me.FillList()
    End Sub

    Private Sub btnFill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFill.Click
        Dim decStartValue As Decimal
        Dim decStepValue As Decimal

        Try
            decStartValue = Decimal.Parse(Me.txtStartValue.Text, Globalization.NumberStyles.Any)
        Catch ex As Exception
            Me.txtStartValue.Text = Nothing
            Me.txtStartValue.Focus()
            Exit Sub
        End Try
        Try
            decStepValue = Decimal.Parse(Me.txtStepValue.Text, Globalization.NumberStyles.Any)
        Catch ex As Exception
            Me.txtStepValue.Text = Nothing
            Me.txtStepValue.Focus()
            Exit Sub
        End Try
        Try
            m_objMyWavelengths.AddRange(decStartValue, CType(numWavelengths.Value, Integer), decStepValue)
        Catch ex As MyWavelengths.WavelengthException
            m_objMyWavelengths.Undo()
            MessageBox.Show(ex.Message, My.Application.Info.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End Try
        Me.FillList()
    End Sub

    Private Sub lvwWavelengths_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvwWavelengths.SelectedIndexChanged
        Me.EnableControls()
    End Sub


    Private Sub EnableControls()
        Me.btnDelete.Enabled = (Me.lvwWavelengths.SelectedIndices.Count > 0)
    End Sub

    Private Sub FillList()
        With Me.lvwWavelengths.Items
            .Clear()
            For intWavelength As Integer = 1 To m_objMyWavelengths.Count
                Dim dblValue As Double = m_objMyWavelengths.Item(intWavelength)
                Dim strItem As String = dblValue.ToString("0.000")

                If Not m_WavelengthList.Contains(dblValue) Then
                    strItem += " *"
                End If
                .Add(intWavelength.ToString).SubItems.Add(strItem)
            Next
        End With
        Me.numWavelengths.Value = m_objMyWavelengths.Count
        Me.EnableControls()
    End Sub

    Private Sub Translate()
        Me.pagSingle.Text = Language.ReadWavelengths("pagSingle")
        Me.lblNewValue.Text = Language.ReadWavelengths("lblNewValue")
        Me.btnAdd.Text = Language.ReadWavelengths("btnAdd")
        Me.btnDelete.Text = Language.ReadWavelengths("btnDelete")
        Me.pagMultiple.Text = Language.ReadWavelengths("pagMultiple")
        Me.lblWavelengths.Text = Language.ReadWavelengths("lblWavelengths")
        Me.lblStartValue.Text = Language.ReadWavelengths("lblStartValue")
        Me.lblStepValue.Text = Language.ReadWavelengths("lblStepValue")
        Me.btnFill.Text = Language.ReadWavelengths("btnFill")
        Me.btnDefault.Text = Language.ReadWavelengths("btnDefault")
        Me.btnOK.Text = Language.ReadMessages("msgOK")
        Me.btnCancel.Text = Language.ReadMessages("msgCANCEL")
    End Sub

End Class